home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261ini.zip / GS_FONTS.PS < prev    next >
Text File  |  1993-05-27  |  18KB  |  538 lines

  1. %    Copyright (C) 1990, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % Font initialization for Ghostscript.
  20.  
  21. % The standard representation for PostScript compatible fonts is described
  22. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  23. % We don't attempt to document this representation here.
  24. % Ghostscript uses Type 1 fonts, except that the external form doesn't use
  25. % eexec encryption and may not even use CharString encryption.
  26.  
  27.  
  28. % Define the default font.
  29. /defaultfontname /Ugly def
  30.  
  31. % Load the font name -> font file name map.
  32. userdict /Fontmap FontDirectory maxlength dict put
  33. /.loadFontmap        % <filename>
  34.  { 2 dict begin
  35.      mark Fontmap
  36.      /;
  37.       { % The stack contains a mark, the dictionary, the font name,
  38.         % the file or alias name, and possibly additional information
  39.     % about the font.
  40.     counttomark 3 sub { pop } repeat .growput
  41.     Fontmap
  42.       } bind def
  43.      3 -1 roll run
  44.    end
  45.    pop pop        % pop the mark and the copy of the dictionary
  46.  } bind def
  47. (Fontmap) .loadFontmap
  48.  
  49. % Ghostscript optionally can load individual CharStrings as they are needed.
  50. % (This is intended primarily for machines with very small memories.)
  51. % This happens if DISKFONTS is true.  In this case, we define another
  52. % dictionary parallel to FontDirectory that retains an open file
  53. % for every font loaded.
  54. /FontFileDirectory 10 dict def
  55.  
  56. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  57. % and UnderlineThickness entries in FontInfo if they aren't there already.
  58. % (This works around the incorrect assumption, made by many word processors,
  59. % that these entries are present in the built-in fonts.)
  60. /.buildfont1x
  61.  { dup /FontInfo known not
  62.     { dup /FontInfo 2 dict .growput }
  63.    if
  64.    dup dup /FontInfo get dup dup
  65.    /UnderlinePosition known exch /UnderlineThickness known and
  66.     { pop pop        % entries already present
  67.     }
  68.     { dup length 2 add dict copy
  69.       dup /UnderlinePosition known not
  70.        { dup /UnderlinePosition 3 index /FontBBox get
  71.          1 get 2 div put        % 1/2 the font descent
  72.        }
  73.       if
  74.       dup /UnderlineThickness known not
  75.        { dup /UnderlineThickness 3 index /FontBBox get
  76.          dup 3 get exch 1 get sub 20 div put    % 1/20 the font height
  77.        }
  78.       if
  79.       1 index /FontInfo get wcheck not { readonly } if
  80.       /FontInfo exch put
  81.     }
  82.    ifelse .buildfont1
  83.  } bind def
  84. % Define definefont.  This is a procedure built on a set of operators
  85. % that do all the error checking and key insertion.
  86. mark
  87.     /.buildfont0 where { pop 0 /.buildfont0 load } if
  88.     /.buildfont1 where { pop 1 /.buildfont1x load } if
  89.     /.buildfont3 where { pop 3 /.buildfont3 load } if
  90. .dicttomark /.buildfontdict exch def
  91. /definefont
  92.  { 1 dict begin count /d exch def    % save stack depth in case of error
  93.     {        % Check for disabled platform fonts.
  94.       NOPLATFONTS
  95.        { dup maxlength 1 index length sub 2 lt { dup .growdict } if
  96.      dup /ExactSize 0 put
  97.        }
  98.        {    % Hack: if the Encoding looks like it might be the
  99.         % Symbol or Dingbats encoding, load those now (for the
  100.         % benefit of platform font matching) just in case
  101.         % the font didn't actually reference them.
  102.      dup /Encoding get length 65 ge
  103.       { dup /Encoding get 64 get
  104.         dup /congruent eq { SymbolEncoding pop } if
  105.         /a9 eq { DingbatsEncoding pop } if
  106.       }
  107.      if
  108.        }
  109.       ifelse
  110.       dup /FontType get //.buildfontdict exch get exec
  111.       DISKFONTS
  112.        { FontFileDirectory 2 index known
  113.           { dup /FontFile FontFileDirectory 4 index get .growput
  114.       }
  115.      if
  116.        }
  117.       if
  118.       readonly
  119.     }
  120.    stopped
  121.     { count d sub { pop } repeat end /invalidfont signalerror }
  122.     { end dup FontDirectory 4 2 roll .growput }
  123.    ifelse
  124.  } odef
  125.  
  126.  
  127. % Ghostscript optionally can load individual CharStrings as they are needed.
  128. % (This is intended primarily for machines with very small memories.)
  129. % Initially, the character definition is the file position of the definition;
  130. % this gets replaced with the actual CharString.
  131. % Note that if we are loading characters lazily, CharStrings is writable.
  132.  
  133. % _Cstring must be long enough to hold the longest CharString for
  134. % a character defined using seac.  This is lenIV + 4 * 5 (for the operands
  135. % of sbw, assuming div is not used) + 2 (for sbw) + 3 * 5 (for the operands
  136. % of seac other than the character codes) + 2 * 2 (for the character codes)
  137. % + 2 (for seac), i.e., lenIV + 43.
  138.  
  139. /_Cstring 60 string def
  140.  
  141. % When we initially load the font, we call
  142. %    <index|charname> <length> <readproc> cskip_C
  143. % to skip over each character definition and return the file position instead.
  144. % This substitutes for the procedure
  145. %    <index|charname> <length> string currentfile exch read[hex]string pop
  146. %      [encrypt]
  147. % What we actually store is fileposition * 1000 + length,
  148. %   negated if the string is stored in binary form.
  149.  
  150. % Older fonts use skip_C rather than cskip_C.
  151. % skip_C takes /readstring or /readhexstring as its third argument,
  152. % instead of the entire reading procedure.
  153. /skipproc_C {string currentfile exch readstring pop} cvlit def
  154. /skip_C
  155.  { //skipproc_C dup 3 4 -1 roll put cvx readonly cskip_C
  156.  } bind def
  157. /cskip_C
  158.  { exch dup 1000 ge 3 index type /nametype ne or
  159.     { % This is a Subrs string, or the string is so long we can't represent
  160.       % its length.  Load it now.
  161.       exch exec
  162.     }
  163.     { % Record the position and length, and skip the string.
  164.       dup currentfile fileposition 1000 mul add
  165.       2 index 3 get /readstring cvx eq { neg } if
  166.       3 1 roll
  167.       dup _Cstring length idiv
  168.        { currentfile _Cstring 3 index 3 get exec pop pop
  169.        } repeat
  170.       _Cstring length mod _Cstring exch 0 exch getinterval
  171.       currentfile exch 3 -1 roll 3 get exec pop pop
  172.     }
  173.    ifelse
  174.  } bind def
  175.  
  176. % Type1BuildGlyph calls load_C to actually load the character definition.
  177.  
  178. /load_C        % <charname> <fileposandlength> -> -
  179.  { dup abs 1000 idiv FontFile exch setfileposition
  180.    CharStrings 3 1 roll
  181.    dup 0 lt
  182.     { neg 1000 mod string FontFile exch readstring }
  183.     { 1000 mod string FontFile exch readhexstring }
  184.    ifelse pop
  185. % If the CharStrings aren't encrypted on the file, encrypt now.
  186.    Private /-| get 0 get
  187.    dup type /nametype ne { dup length 5 sub 5 exch getinterval exec } { pop } ifelse
  188.    dup 4 1 roll put
  189. % If the character is defined with seac, load its components now.
  190.    mark exch seac_C
  191.    counttomark
  192.     { StandardEncoding exch get dup CharStrings exch get
  193.       dup type /integertype eq { load_C } { pop pop } ifelse
  194.     } repeat
  195.    pop        % the mark
  196.  } bind def
  197.  
  198. /seac_C        % charstring -> achar bchar ..or nothing..
  199.  { dup length _Cstring length le
  200.     { 4330 exch _Cstring .type1decrypt exch pop
  201.       dup dup length 2 sub 2 getinterval <0c06> eq    % seac
  202.        { dup length
  203.          Private /lenIV known { Private /lenIV get } { 4 } ifelse
  204.      exch 1 index sub getinterval
  205. % Parse the string just enough to extract the seac information.
  206. % We assume that the only possible operators are hsbw, sbw, and seac,
  207. % and that there are no 5-byte numbers.
  208.      mark 0 3 -1 roll
  209.       { exch
  210.          { { dup 32 lt
  211.               { pop 0 }
  212.           { dup 247 lt
  213.              { 139 sub 0 }
  214.              { dup 251 lt
  215.             { 247 sub 256 mul 108 add 1